{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# PyQt Plotting Example"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This script is used mainly to test the PyQt based plotting tools.\n",
    "These tools were originally developed for displaying images and were extended to\n",
    "work with echogram data.\n",
    "\n",
    "Controls:\n",
    "\n",
    "    CTRL + Mouse Wheel zooms in.out\n",
    "    ALT + Click and drag will pan\n",
    "\n",
    "\n",
    "WARNING: This code currently uses PyQt4 and is incompatible with Qt5\n",
    "\n",
    "The plan is to make the qt plotting tools compatible with Python3/Qt5\n",
    "but they currently only work in Python2/PyQt4.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Setup"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "ename": "ModuleNotFoundError",
     "evalue": "No module named 'PyQt4'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mModuleNotFoundError\u001b[0m                       Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-2-738d65cb5735>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mfrom\u001b[0m \u001b[0mPyQt4\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mQtCore\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      2\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mPyQt4\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mQtGui\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      3\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mecholab2\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0minstruments\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mEK60\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      4\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mecholab2\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mplotting\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mqt\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mechogram_viewer\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'PyQt4'"
     ]
    }
   ],
   "source": [
    "from PyQt4.QtCore import *\n",
    "from PyQt4.QtGui import *\n",
    "from echolab2.instruments import EK60\n",
    "from echolab2.plotting.qt import echogram_viewer"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Read the data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Specify a raw file. This file is big, it takes a bit to load and display.\n",
    "rawfiles = ['./data/ES60/L0059-D20140518-T181425-ES60.raw']\n",
    "\n",
    "# Create an instance of the EK60 instrument.\n",
    "ek60 = EK60.EK60()\n",
    "\n",
    "# Read the data.\n",
    "ek60.read_raw(rawfiles)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Parse the data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Get the 38 kHz raw data.\n",
    "raw_data_38 = ek60.get_raw_data(channel_number=1)\n",
    "\n",
    "# Get Sv data.\n",
    "Sv_38 = raw_data_38.get_Sv()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Create an application instance.\n",
    "app = QApplication([])\n",
    "\n",
    "# Create the main application window.\n",
    "window = echogram_viewer.echogram_viewer(Sv_38)\n",
    "window.show()\n",
    "\n",
    "# Start event processing.\n",
    "app.exec_()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
